import React from 'react';
import pageTabUtil from '@/utils/pageTabUtil';

export default function useTabChange(callback) {
    const handleCallback = React.useCallback(
        tabKey => {
            if (callback) callback(tabKey);
        },
        [callback]
    );

    React.useEffect(() => {
        pageTabUtil.sub(pageTabUtil.eventMap.CHANGE_TAB, handleCallback);
        return () => {
            pageTabUtil.unSub(pageTabUtil.eventMap.CHANGE_TAB, handleCallback);
        };
    }, []);
}
